import type { VNode } from 'vue';
import type {
  ColProps,
  FormItemProps,
  AutoCompleteProps as _AutoCompleteProps,
  ButtonProps as _ButtonProps,
  CalendarProps as _CalendarProps,
  CascaderProps as _CascaderProps,
  CheckboxGroupProps as _CheckboxGroupProps,
  CheckboxProps as _CheckboxProps,
  ColProps as _ColProps,
  DatePickerProps as _DatePickerProps,
  InputNumberProps as _InputNumberProps,
  InputProps as _InputProps,
  RadioGroupProps as _RadioGroupProps,
  RateProps as _RateProps,
  RowProps as _RowProps,
  SelectProps as _SelectProps,
  SliderProps as _SliderProps,
  SwitchProps as _SwitchProps,
  TextAreaProps as _TextAreaProps,
  TimePickerProps as _TimePickerProps,
  TimeRangePickerProps as _TimeRangePickerProps,
  TransferProps as _TransferProps,
  TreeSelectProps as _TreeSelectProps,
  UploadProps as _UploadProps,
} from 'ant-design-vue';

export type FormState = Record<string, any>;
interface BaseProps<T extends FormState>
  extends Omit<FormItemProps, 'hidden | name | prop'> {
  field: keyof T | (string | number)[];
  hide?: boolean | ((state: T, modalType: string) => boolean);
  customRender?: (state: T) => VNode;
  formItemRender?: () => VNode;
  disabled?: boolean | ((state: T) => boolean);
  [key: string]: any;
  colProps?: ColProps;
}

export interface InputProps<T extends FormState> extends BaseProps<T> {
  type: 'input';
  props?: _InputProps;
}

export interface Textarea<T extends FormState> extends BaseProps<T> {
  type: 'textarea';
  props?: _TextAreaProps;
}

export interface SelectProps<T extends FormState> extends BaseProps<T> {
  type: 'select';
  props?: _SelectProps;
}

export interface RadioProps<T extends FormState> extends BaseProps<T> {
  type: 'radio';
  props?: _RadioGroupProps;
}

export interface TreeSelectProps<T extends FormState> extends BaseProps<T> {
  type: 'treeSelect';
  props?: _TreeSelectProps;
}

export interface InputNumberProps<T extends FormState> extends BaseProps<T> {
  type: 'number';
  props?: _InputNumberProps;
}

export interface DateRangeProps<T extends FormState> extends BaseProps<T> {
  type: 'dateRange';
  props?: _DatePickerProps;
}

export interface Checkbox<T extends FormState> extends BaseProps<T> {
  type: 'checkbox';
  props?: Partial<_CheckboxProps>;
}

export interface CheckboxGroupProps<T extends FormState> extends BaseProps<T> {
  type: 'checkboxGroup';
  props?: _CheckboxGroupProps;
}

export interface SwitchProps<T extends FormState> extends BaseProps<T> {
  type: 'switch';
  props?: _SwitchProps;
}

export interface CascaderProps<T extends FormState> extends BaseProps<T> {
  type: 'cascader';
  props?: _CascaderProps;
}

export interface DatePickerProps<T extends FormState> extends BaseProps<T> {
  type: 'date';
  props?: _DatePickerProps;
}

export interface Noop<T extends FormState> extends Pick<BaseProps<T>, 'hide'> {
  type: 'noop';
}

export type ItemProps<T extends FormState = any> =
  | Noop<T>
  | InputProps<T>
  | SelectProps<T>
  | RadioProps<T>
  | Textarea<T>
  | TreeSelectProps<T>
  | InputNumberProps<T>
  | DateRangeProps<T>
  | Checkbox<T>
  | CheckboxGroupProps<T>
  | SwitchProps<T>
  | CascaderProps<T>
  | DatePickerProps<T>;
